{extend name="main/index" /}
{block name="main"}
<div class="main-content">
    <div class="breadcrumbs" id="breadcrumbs">
        <script type="text/javascript">
            try{ace.settings.check('breadcrumbs' , 'fixed')}catch(e){}
        </script>

        <ul class="breadcrumb">
            <li>
                <i class="icon-home home-icon"></i>
                <a href="{:url('admin/safe/index')}">安全计划管理</a>
            </li>
        </ul><!-- .breadcrumb -->

        <div class="nav-search" id="nav-search">
            <form class="form-search">
                <span class="input-icon">
                    <input type="text" placeholder="Search ..." class="nav-search-input" id="nav-search-input" autocomplete="off" />
                    <i class="icon-search nav-search-icon"></i>
                </span>
            </form>
        </div><!-- #nav-search -->
    </div>

    <div class="page-content">
        <div class="row">
            <div class="col-xs-12">
                <div class="row">
                    <div class="col-xs-12">
                        <div class="table-responsive">
                            <a href="{:url('admin/safe/addsafe')}" class="btn btn-info">添加安全计划</a>
                            <br><br>
                            <table id="sample-table-2" class="table table-striped table-bordered table-hover">
                                <thead>
                                    <tr>
                                        <th>ID</th>
                                        <th>项目名称</th>
                                        <th class="hidden-480">工作要求</th>

                                        <th>
                                            工作内容
                                        </th>
                                        <th class="hidden-480">工作记录</th>
                                        <th class="hidden-480">状态</th>
                                        <th class="hidden-480"><i class="icon-time bigger-110 hidden-480"></i>日期</th>
                                        <th class="hidden-480">操作</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    {volist name="safe" id="v"}
                                    <tr>
                                        <td>{$v['id']}</td>
                                        <td>{$v['project_name']}</td>
                                        <td>{$v['safety_job_requirement']}</td>
                                        <td>
                                            <button  data-id="{$v['id']}" class="btn btn-xs btn-primary show-btn" data-toggle="modal"
                                data-target="#myModal" >查看更多</button>

                                        </td>
                                        <td>{$v['safety_job_logging']}</td>
                                        <td>
                                            {$v['status']==1?'开启':'关闭'}
                                        </td>
                                        <td>{$v['date']}</td>
                                        <td>
                                            <a href="{:url('admin/safe/edit', ['id' => $v['id']])}" class="btn btn-primary btn-xs">修改</a> | 
                                            <button data-id="{$v['id']}" class="btn btn-danger del-btn btn-xs">删除</button>
                                            
                                        </td>
                                    </tr>
                                    {/volist}
                                </tbody>
                            </table>
                        </div>
                        {$safe->render()}
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" id="myModalLabel">
                    项目 <u></u> 的安全工作内容
                </h4>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-md-12">
                        <u>安全工作内容</u>:<span></span>
                        <hr>
                        <b style="font-size:24px;"></b>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" data-dismiss="modal">关闭</button>
            </div>
        </div>
    </div>
</div>

{/block}



{block name="myjs"}
{js href="/static/admin/assets/js/toastr.min.js"}
<script>
    $(function(){
        $('.show-btn').click(function () {
            var ac_id = $(this).attr('data-id');
            console.log('我要查询: ' + ac_id + '的项目工作内容');
            showAjax(ac_id);
        });

        $('.del-btn').click(function () {
            var ac_id = $(this).attr('data-id');
            console.log('我要删除: ' + ac_id + '的项目');
            if (confirm('你确定要 [ 删 除 ] 吗?')) {
                var obj = $(this).parents('tr');
                // console.log(obj);
                delAjax(ac_id, obj);
            }
        });

    });

    // 查看项目的安全工作内容
    function showAjax(id) {
        $.ajax({
            type: 'get',
            url: '/Safe/' + id,
            dataType: 'json',
            success: function (data) {
                console.log(data);
                if (data.status) {
                    //  modal填充
                    $('.modal-title u').html(data.title);
                    var msg = data.data;
                    $('.modal-body span').html(msg);
                } else {
                    //  modal填充
                    $('.modal-title u').html(data.title);
                    $('.modal-body').html(data.datas);
                }
            },
            error: function () {
                alert('AJAX执行失败');
            }
        });
    }

    // 执行ajax删除
    function delAjax(id, obj) {
        $.ajax({
            type: 'delete',
            url: '/Safe/' + id,
            dataType: 'json',
            success: function (data) {
                console.log(data);
                if (data.status) {
                    toastr.success(data.info);
                    obj.remove();
                } else {
                    toastr.error(data.info, 'FBI WARNING:');
                }
            },
            error: function () {
                alert('AJAX执行失败');
            }
        });
    }

</script>

{/block}





